package com.ztz.mynewdemo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.loopj.android.image.SmartImageView;
import com.ztz.mynewdemo.R;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by wqewqe on 2017/12/19.
 */

public class DetailAdapter extends RecyclerView.Adapter<DetailAdapter.ViewHolder> {
    Context context;
    ArrayList<String> images;
    ArrayList<String> headPortrait;
    ArrayList<String> titles;
    ArrayList<String> author;
    ArrayList<String> contents;

    public DetailAdapter(Context context, ArrayList<String> images, ArrayList<String> headPortrait, ArrayList<String> titles, ArrayList<String> author, ArrayList<String> contents) {
        this.context = context;
        this.images = images;
        this.headPortrait = headPortrait;
        this.titles = titles;
        this.author = author;
        this.contents = contents;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_jianshu, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
//        Glide.with(context).load(images.get(position))
//                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
//                .centerCrop()
//                .into(holder.iv_img);
//        Glide.with(context).load(headPortrait.get(position))
//                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
//                .centerCrop()
//                .transform(new GlideCircleTransform(context))
//                .into(holder.ivPortrait);
        holder.ivImg.setImageUrl(images.get(position));
        holder.ivPortrait.setImageUrl(headPortrait.get(position));
        holder.tvTitle.setText(titles.get(position));
        holder.tvName.setText(author.get(position));
        holder.tcContent.setText(contents.get(position));
    }

    @Override
    public int getItemCount() {
        return titles.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_portrait)
        SmartImageView ivPortrait;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tc_content)
        TextView tcContent;
        @BindView(R.id.iv_img)
        SmartImageView ivImg;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
